﻿namespace Example.Cryptography
{
    using System;

    using Xunit;

    public class SaltFacts
    {
        [Fact]
        public void ctor_byte()
        {
            Assert.NotNull(new Salt(new byte[]
                                        {
                                            1, 2, 3
                                        }));
        }

        [Fact]
        public void ctor_byteEmpty()
        {
            Assert.NotNull(new Salt(new byte[]
                                        {
                                        }));
        }

        [Fact]
        public void ctor_byteNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Salt(null as byte[]));
        }

        [Fact]
        public void ctor_string()
        {
            Assert.NotNull(new Salt("test"));
        }

        [Fact]
        public void ctor_stringEmpty()
        {
            Assert.NotNull(new Salt(string.Empty));
        }

        [Fact]
        public void ctor_stringNull()
        {
            Assert.Throws<ArgumentNullException>(() => new Salt(null as string));
        }

        [Fact]
        public void op_Fresh()
        {
            const int expected = 10;
            var actual = Salt.Fresh().ToBytes().Length;

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void op_Fresh_int()
        {
            const int expected = 25;
            var actual = Salt.Fresh(expected).ToBytes().Length;

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void op_Fresh_intZero()
        {
            Assert.Throws<ArgumentOutOfRangeException>(() => Salt.Fresh(0));
        }

        [Fact]
        public void op_ToBytes()
        {
            var expected = Convert.FromBase64String("test");
            var actual = new Salt(expected).ToBytes();

            Assert.Equal(expected, actual);
        }

        [Fact]
        public void op_ToString()
        {
            const string expected = "test";
            var actual = new Salt(expected).ToString();

            Assert.Equal(expected, actual);
        }
    }
}